package com.zy.untils;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.graphics.BitmapFactory;

import com.zy.base.R;

public class MyNotificationUtils {

    /**
     * 启动前台服务
     * @param context 服务
     */
    public static void setNotification(Service context){
        String CHANNEL_ID = "888";
        String CHANNEL_Name = "channel_name";
        NotificationChannel channel = null;
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            channel = new NotificationChannel(CHANNEL_ID, CHANNEL_Name, NotificationManager.IMPORTANCE_HIGH);
            manager.createNotificationChannel(channel);
            builder = new Notification.Builder(context,CHANNEL_ID);
        }else {
            builder=new Notification.Builder(context);
        }


        builder.setContentTitle("This is content file");
        builder.setContentText("This is content text");
        builder.setWhen(System.currentTimeMillis());
        builder.setSmallIcon(R.mipmap.default_image);
        Notification notification = builder.build();
        context.startForeground(888,notification);
    }
}
